<script>
	import Vue from 'vue'
	import pageAnimation from './components/page-animation'
	export default {
		globalData: {
			debug: true,//发布时必须改为false!!!
			sceneId: '',
			departname: "", //所属公司名称
			token: "", // 有效token
			username: "", //用户名
			orgcode: "" //所属公司代码
		},
		mixins:[pageAnimation],
		onLaunch: function() {
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif

					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif		

					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})
			//获取用户授权
			let tmpUrlSearch = window.location.search; // 得到：?sceneid=h5&wxcode=xxx&puid=fff
			let tmpParas = GetRequestParameters(tmpUrlSearch);
			let tmpSceneID = tmpParas["code"]; //提取code参数, 用于获取openid

			// console.log("tmpUrlSearch = " + tmpUrlSearch)
			// console.log("tmpParas = " + tmpParas)
			// console.log("tmpSceneID = " + tmpSceneID)

			if (tmpSceneID != null && typeof(tmpSceneID) != 'undefined') {
				// console.log("111111111")
				//将获取到的SceneID保存下来
				getApp().globalData.sceneId = tmpSceneID;
			} else {
				//重定向拿code
				if (getApp().globalData.debug) return;
				window.location.href = this.$constant.AUTHORIZE;
				return
			}

		},
		onShow: function() {
			//当 uni-app 启动，或从后台进入前台显示
			console.log('App Show')
		},
		onHide: function() {
			//当 uni-app 从前台进入后台
			console.log('App Hide')
		}
	}

	export const GetRequestParameters = (locationsearch) => {
		let url = locationsearch;
		let theRequest = new Object();
		if (url.indexOf("?") != -1) {
			let str = url.substr(1);
			let strs = str.split("&");
			for (let i = 0; i < strs.length; i++) {
				theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]);
			}
		}
		return theRequest;
	}
</script>

<style>
	/*每个页面公共css */
	@import "components/colorui/main.css";
	@import "components/colorui/icon.css";
	@import "components/ly-tree/ly-tree.css";
</style>
